import Ability from '@ohos.application.Ability';
import display from '@ohos.display';

var TAG = "Dialog_MainAbility:";

export default class MainAbility extends Ability {
    onCreate(want, launchParam) {
        console.log(TAG + "MainAbility onCreate, ability name is " + want.abilityName + ".");
        globalThis.context = this.context;
        globalThis.abilityWant = want;

        globalThis.screenWidth =  display.getDefaultDisplaySync().width
        globalThis.screenHeight = display.getDefaultDisplaySync().height

        console.error(TAG, `onCreate globalThis.screenWidth: ${JSON.stringify(globalThis.screenWidth)} globalThis.screenHeight: ${JSON.stringify(globalThis.screenHeight)}`)
    }

     onWindowStageCreate(windowStage) {
        // Main window is created, set main page for this ability
        console.error(TAG, `onWindowStageCreate globalThis.screenWidth: ${JSON.stringify(globalThis.screenWidth)} globalThis.screenHeight: ${JSON.stringify(globalThis.screenHeight)}`)

        windowStage.setUIContent(this.context, "pages/powerdialog", null);
        console.log(TAG + "MainAbility onWindowStageCreate.");
    }

    onForeground() {
        // Ability has brought to foreground
        console.log(TAG + "MainAbility onForeground.");
    }

    onBackground() {
        // Ability has back to background
        console.log(TAG + "MainAbility onBackground.");
        this.context.terminateSelf();
    }

    onDestroy() {
        console.log(TAG + "MainAbility onDestroy.");
    }

    onWindowStageDestroy() {
        // Main window is destroyed, release UI related resources
        console.log(TAG + "MainAbility onWindowStageDestroy.");
    }
};
